#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int son[6200010][2];

void insert(int x, int son[6200010][2], int& idx)
{
    int p = 0;
    for (int i = 30; i >= 0; i--)
    {
        int& s = son[p][x >> i & 1];
        if (!s)  s = ++idx;
        p = s;
    }
}

int search(int x, int son[6200010][2])
{
    int p = 0, res = 0;
    for (int i = 30; i >= 0; i--)
    {
        int s = x >> i & 1;
        if (son[p][!s])
        {
            res += 1 << i;
            p = son[p][!s];
        }
        else p = son[p][s];
    }
    return res;
}

int findMaximumXOR(vector<int>& nums) {
    memset(son, 0, sizeof son);
    int idx = 0;
    for (int num : nums)
        insert(num, son, idx);

    int res = 0;
    for (int num : nums)
        res = max(res, search(num, son));
    return res;
}
